package reflect;

import java.util.ArrayList;
import java.util.Scanner;

public class ReflecetDemo2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {

        //Class cls= ArrayList.class;

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入类名");
        String className = sc.nextLine();
        Class cls=Class.forName(className);
        //2、类对象提供了方法newInstance()可以进行实例化
        Object obj = cls.newInstance();//只能使用无参构造器实例化
        System.out.println(obj);
    }
}
